from pydantic import BaseModel, Field, model_validator


class PageModel(BaseModel):
    page: int = Field(1, title='页码', gt=0)
    page_size: int = Field(10, title='每页条数')

    @property
    def offset(self):
        return (self.page - 1) * self.page_size

    @model_validator(mode='after')
    def verify_size(self, max_size=10000):
        if self.page * self.page_size >= max_size:
            raise ValueError(f'总数应小于{max_size}')
        return self


if __name__ == '__main__':
    page = PageModel(page=1, page_size=1000)
    print(page)
